package com.sjd.web.api.account;

import com.sjd.common.core.controller.BaseController;
import com.sjd.common.core.domain.AjaxResult;
import com.sjd.common.core.page.TableDataInfo;
import com.sjd.mall.domain.SjdAccountGlodenBeanDetailsDO;
import com.sjd.mall.domain.dto.account.AccountRechargeQueryResponseDTO;
import com.sjd.mall.domain.dto.account.AccountRechargeRequestDTO;
import com.sjd.mall.domain.dto.account.BasePageHelperDTO;
import com.sjd.mall.service.account.AccountGoldenBeanService;
import com.sjd.mall.domain.dto.account.CreateRechargeOrderRequestDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
  *@CalssName WxGoldenBeanApi
  *@Description 小程序金豆API
  *@Authot genglong
  *@Date 2022/1/18 15:49
  *@Version 1.0
  **/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/weixin/api/ma/goldenbean")
@Api(value = "goldenbean", tags = "小程序金豆API")
public class WxGoldenBeanApi extends BaseController {

    private final AccountGoldenBeanService accountGoldenBeanService;

    /**
     * 创建订单
     */
    @ApiOperation(value = "创建订单")
    @PostMapping("/createOrder")
    public AjaxResult createOrder(@Validated @RequestBody CreateRechargeOrderRequestDTO requestDTO) {
        try {
            SjdAccountGlodenBeanDetailsDO sjdAccountGlodenBeanDetailsDO = accountGoldenBeanService.createOrder(requestDTO);
            return AjaxResult.success(sjdAccountGlodenBeanDetailsDO);
        } catch (Exception e) {
            log.error("用户创建订单出现异常，异常信息===>{}", e.getMessage());
            return AjaxResult.error("用户创建订单出现异常");
        }
    }

    /**
     * 下单充值
     * @param requestDTO
     * @return
     */
    @ApiOperation(value = "下单充值")
    @PostMapping("/recharge")
    public AjaxResult recharge(@Validated @RequestBody AccountRechargeRequestDTO requestDTO) {
        try {
            return AjaxResult.success(accountGoldenBeanService.recharge(requestDTO));
        } catch (Exception e) {
            log.error("用户下单充值出现异常，异常信息===>{}", e.getMessage());
            return AjaxResult.error("用户下单充值出现异常");
        }
    }

    /**
     * 支付结果通知
     * @param request
     * @return
     */
    @ApiOperation(value = "支付结果通知")
    @PostMapping("/payResultNotify")
    public String payResultNotify(HttpServletRequest request){
        return accountGoldenBeanService.payResultNotify(request);
    }

    /**
     * 金豆明细查询
     * @return
     */
    @ApiOperation(value = "金豆明细查询")
    @GetMapping("/queryGoldenBeanOderList")
    public TableDataInfo queryGoldenBeanOderList(){
        startPage();
        List<AccountRechargeQueryResponseDTO> resultList = accountGoldenBeanService.queryGoldenBeanOderList();
        return getDataTable(resultList);
    }
}
